package com.horay.springbootdemo.web.servlet.controller;

import com.horay.springbootdemo.web.servlet.common.controller.BaseServlet;
import com.horay.springbootdemo.web.servlet.common.result.ResultBody;
import com.horay.springbootdemo.web.servlet.service.IndexService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StopWatch;

import javax.servlet.annotation.WebServlet;

/**
 * 首页推广Servlet
 *
 * @author heyingcheng
 * @date 2019/9/11 1:15
 */
@Slf4j
@WebServlet(name = "index", urlPatterns = {"/index"}, loadOnStartup = 1)
public class IndexController extends BaseServlet {

    @Autowired
    private IndexService indexService;

    @Override
    public ResultBody<String> execute(String requestBody) {
        StopWatch stopWatch = new StopWatch();
        stopWatch.start("IndexController.execute");
        String indexInfo = indexService.getIndexInfo();
        ResultBody<String> result = new ResultBody<>();
        result.setData(indexInfo);
        stopWatch.stop();
        log.info(stopWatch.prettyPrint());
        log.info("IndexInfo interface response message, result:[{}]", result);
        return result;
    }

}
